package com.yy.service.impl;



import com.yy.domain.User;
import com.yy.mapper.UserMapper;
import com.yy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    /**
     * 充钱
     *
     * @param userId
     * @param money
     * @return
     */
    @Override
    public int dorecharge(Integer userId, Integer money) throws Exception {
        User user=this.userMapper.selectByPrimaryKey(userId);
        if (ObjectUtils.isEmpty(user)){
            throw new Exception("当前用户不存在");
        }
        Long finalMoney=user.getBanlance()+money;
        user.setBanlance(finalMoney);
        return this.userMapper.updateByPrimaryKey(user);
    }

    /**
     * @param userId
     * @return
     */
    @Override
    public User getMember(Integer userId) {
        return this.userMapper.selectByPrimaryKey(userId);
    }

    /**
     * @param user
     * @return
     */
    @Override
    public int updateMember(User user) {
        return this.userMapper.updateByPrimaryKey(user);
    }
}
